//
// Created by xili on 2024/8/22 11:23.
// GO BIG OR GO HOME.
//
#include "leetcode.h"

class Solution {
public:
    vector <vector<int>> groupThePeople(vector<int> &groupSizes) {
        unordered_map<int, vector<int>> ump;
        int n = groupSizes.size();
        for (int i = 0; i < n; i++) {
            ump[groupSizes[i]].emplace_back(i);
        }
        vector <vector<int>> ans;
        for (auto &[s, g]: ump) {
            int cnt = g.size() / s;
            for (int i = 0; i < cnt; i++) {
                vector<int> cur;
                int start = i * s;
                for (int j = 0; j < s; j++) {
                    cur.emplace_back(g[j + start]);
                }
                ans.emplace_back(cur);
            }
        }
        return ans;
    }
};